<!--
 * @FilePath     : /study_code/vue2.x/transition-appear copy.html
 * @Description  : 初始渲染，添加自定义类
 * @Date         : 2025-05-03 08:21:19
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-05-03 08:21:19
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <style>
      .custom-appear,
      .v-enter,
      .v-leave-to {
        opacity: 0;
      }

      .custom-appear-to,
      .v-enter-to,
      .v-leave {
        opacity: 1;
      }

      .custom-appear-active,
      .v-enter-active,
      .v-leave-active {
        transition: all 5s;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <button @click="show = !show">toggle</button>
      <transition
        @before-appear="beforeAppearHook"
        @appear="appearHook"
        @after-appear="afterAppearHook"
        @appear-cancelled="appearCancelledHook"
      >
        <p v-if="show">Demo</p>
      </transition>
    </div>

    <script src="/vue/dist/vue.min.js"></script>
    <script src="./common.js"></script>
    <script>
      var app = new Vue({
        el: '#app',
        data: function () {
          return { show: true }
        },
        methods: {
          /**
           * @brief: 初始化过渡 - 之前
           * @param {Object} el transition 包裹的过渡内容 —— DOM元素对象
           */
          beforeAppearHook: function (el) {
            console.log(el)
            console.log('beforeAppearHook')
            // debugger;
          },
          /**
           * @brief: 初始化过渡 - 之时
           * @param {Object} el transition 包裹的过渡内容 —— DOM元素对象
           * @param {Function} done 回调函数 异步的回调
           * !必须使用 done 进行回调。（否则，它们将被同步调用，过渡会立即完成。）
           */
          appearHook: function (el, done) {
            console.log(el)
            console.log('appearHook')
            el.addEventListener('transitionend', () => {
              done()
            })
            // debugger;
          },
          /**
           * @brief: 初始化过渡 - 之后
           * @param {Object} el transition 包裹的过渡内容 —— DOM元素对象
           */
          afterAppearHook: function (el) {
            console.log(el)
            console.log('afterAppearHook')
          },
          /**
           * @brief: 初始化过渡 - 取消
           * @param {Object} el transition 包裹的过渡内容 —— DOM元素对象
           */
          appearCancelledHook: function (el) {
            console.log(el)
            console.log('appearCancelledHook')
          },
        },
      })
    </script>
  </body>
</html>
